package lucius.work.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.hibernate.Session;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import lucius.work.entity.user;
import lucius.work.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController {

	@Resource(name = "userService")
	UserService userService;

	@RequestMapping("/login.do")
	public ModelAndView login(HttpServletRequest req, HttpServletResponse response,HttpSession seesion) throws Exception {
		String username = req.getParameter("username");
		String password = req.getParameter("password");
		User u = userService.findByUserName(username, password);
		if (u!=null) {
			seesion.setAttribute("user", u);
			return new ModelAndView("html/success");
		}
		return new ModelAndView("html/error");
	}

	@RequestMapping("/list.do")
	public ModelAndView list() {
		return new ModelAndView("html/login");
	}
}
